# Thank you
# http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate

module ActsAsFerret
  module ClassMethods
  
    def paginate_search(query, options = {})
      options, page, per_page = wp_parse_options!(options)
      pager = WillPaginate::Collection.new(page, per_page, nil)
      options.merge!(:offset => pager.offset, :limit => per_page)
      result = result = find_by_contents(query, options)
      returning WillPaginate::Collection.new(page, per_page, result.total_hits) do |final_pager|
        final_pager.replace result
        def final_pager.total_hits
          total_entries()
        end
      end
    end
    
  end
end
